package com.xn.app.muying.adpter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xn.app.muying.R;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 个人页面功能模块适配器
 * Created by gaoge on 17/4/13.
 */

public class MyFunctionAdapter extends BaseAdapter {
    LayoutInflater lf = null;
    ArrayList<HashMap<String, String>> getData = new ArrayList<HashMap<String, String>>();
    ViewHolder viewHolder = null;

    public MyFunctionAdapter(Context context,
                               ArrayList<HashMap<String, String>> getData) {
        lf = LayoutInflater.from(context);
        this.getData = getData;
    }

    @Override
    public int getCount() {
        return getData.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @SuppressLint("InflateParams")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = lf.inflate(R.layout.function_grid_item, null);
            viewHolder.textview = (TextView) convertView.findViewById(R.id.textview);
            viewHolder.imageview = (ImageView) convertView.findViewById(R.id.imageview);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.textview.setText(getData.get(position).get("name"));
        if(getData.get(position).get("image")!=null&&!getData.get(position).get("image").equals("")){
            viewHolder.imageview.setImageResource(Integer.parseInt(getData.get(position).get("image")));
        }
        return convertView;
    }
}

/**
 * 包装类
 */
   class ViewHolder {
    public TextView textview = null;
    public ImageView imageview = null;
}
